//   -   3 (-   )
{$CLEO}
var
    17@ : Integer
    18@ : Integer
    6@ : Integer
    8@ : Integer
    29@ : Integer
    30@ : Integer
    25@ : Integer
end
const
    Player_WAS_in_front_of_red_traffic_light = 17@
    Traffic_light_type = 18@                             //   1 or 2
    Type_of_red_traffic_light = 6@                      // 0,1,2,3         0 - both not red       3 - both red
    Player_IS_in_front_of_red_traffic_light = 8@
    Traffic_light_model = 25@
end
19@ = 30000.0
20@ = 30000.0
//---------------------------------------------------------------------------------------------------- 
while true
    wait 0
    if
        player.Defined($PLAYER_CHAR)
    then
        if and
            actor.Driving($PLAYER_ACTOR)
            84A7:   not actor $PLAYER_ACTOR driving_boat 
            84C8:   not actor $PLAYER_ACTOR driving_flying_vehicle
        then
            if or
                89AE: not actor $PLAYER_ACTOR driving_train 
                actor.DrivingVehicleType($PLAYER_ACTOR, #TRAM)
            then
                03C0: 28@ = actor $PLAYER_ACTOR car 
                if
                    8ABD: not vehicle 28@ siren_on
                then
                    //--------------------------------------------------------------------------  
                    actor.StorePos($PLAYER_ACTOR 0@ 1@ 2@)
                    0509: 14@ = distance_between_XY 0@ 1@ and_XY 19@ 20@
                    if
                        gosub @GET_RANDOM_OBJECT
                    then
                        23@ = 0
                        0085: Traffic_light_model = 31@ // (int)           
                        0087: 19@ = 12@ // (float)
                        0087: 20@ = 13@ // (float)
                        0087: 27@ = 26@ // (float)
                        27@ += 1.0
                        0509: 14@ = distance_between_XY 0@ 1@ and_XY 19@ 20@
                        0176: 24@ = object 9@ Z_angle
                        02F6: 10@ = cosine 24@ // (float)  
                        02F7: 22@ = sine 24@ // (float)  
                        0073: 10@ /= 22@ // (float)    
                        //----------------------------------  
                        if and
                            24@ >= 60.0
                            24@ <= 150.0
                        then
                            Traffic_light_type = 2
                        else
                            if and
                                24@ >= 240.0
                                24@ <= 330.0
                            then
                                Traffic_light_type = 2
                            else
                                Traffic_light_type = 1
                            end
                        end         
                    end
                    //-----------------------------------------------------------------     
                    actor.StorePos($player_actor 0@ 1@ 2@)
                    if and          
                        14@ < 30.0  //     
                        06BD: no_obstacles_between 0@ 1@ 2@ and 19@ 20@ 27@ solid 1 car 0 actor 0 object 0 particle 0
                        //        
                    then   //     
                    else
                        23@ = 0
                        continue
                    end
                    //------------------------    
                    0087: 22@ = 0@ // (float)
                    0063: 22@ -= 19@ // (float) 
                    006B: 22@ *= 10@ // (float)
                    005B: 22@ += 20@ // (float)
                    if or
                        24@ < 90.0
                        24@ > 270.0
                    then
                        if
                            0025:   22@ > 1@ // (float)    Y_act < tg_Z_tl*(X_act-X_tl)+Y_tl
                        then
                            Player_IS_in_front_of_red_traffic_light = True    
                        else
                            Player_IS_in_front_of_red_traffic_light = False
                        end
                    else
                        if
                            24@ == 90.0
                        then
                            if
                                0025:   0@ > 19@ // (float)    X_act > X_tl
                            then
                                Player_IS_in_front_of_red_traffic_light = True 
                            else
                                Player_IS_in_front_of_red_traffic_light = False
                            end
                        else
                            if
                                24@ == 270.0
                            then
                                if
                                    0025:   19@ > 0@ // (float)    X_act < X_tl
                                then
                                    Player_IS_in_front_of_red_traffic_light = True 
                                else
                                    Player_IS_in_front_of_red_traffic_light = False
                                end
                            else   //  Z > 90  AND Z < 270
                                if
                                    0025:   1@ > 22@ // (float)    Y_act > tg_Z_tl*(X_act-X_tl)+Y_tl
                                then
                                    Player_IS_in_front_of_red_traffic_light = True    
                                else
                                    Player_IS_in_front_of_red_traffic_light = False
                                end
                            end
                        end
                    end    
                    //------------------------------------------------------------------------
                    if
                        23@ == 0
                    then 
                        if or      //  ,      (  )
                            Traffic_light_model == 3855
                            Traffic_light_model == 1315
                            Traffic_light_model == 1352
                            Traffic_light_model == 1350
                            Traffic_light_model == 1351
                            Traffic_light_model == 3516
                        then
                            if
                                Player_IS_in_front_of_red_traffic_light == True
                            then
                                23@ = 1
                            end
                        else
                            if or   //  ,     ,  
                                Traffic_light_model == 1283
                                Traffic_light_model == 1284
                            then                                
                                23@ = 1
                            end
                        end
                    else
                        if
                            23@ == 2
                        then
                            if
                                Player_IS_in_front_of_red_traffic_light <> Player_WAS_in_front_of_red_traffic_light 
                            then
                                23@ = 3
                            end
                        end    
                    end
                    Player_WAS_in_front_of_red_traffic_light = Player_IS_in_front_of_red_traffic_light   
                    //---------------------------     1  2
                    0AA7: call_function 0x49D3A0 num_params 0 pop 0 29@   //  2 (-)
                    0AA7: call_function 0x49D350 num_params 0 pop 0 30@   //  1 (-)
                    for 16@ = 8 to 31
                        08C3: clear 29@ bit 16@
                        08C3: clear 30@ bit 16@
                    end  //  : 0 - , 1 - , 2 - 
                    if
                        30@ == 2
                    then
                        if
                            29@ == 2
                        then
                            Type_of_red_traffic_light = 3 // both are red
                        else
                            Type_of_red_traffic_light = 1
                        end
                    else
                        if
                            29@ == 2
                        then
                            Type_of_red_traffic_light = 2
                        else
                            Type_of_red_traffic_light = 0
                        end            
                    end    
                    //--------------------------------------------------------------------------
                    if or
                        Type_of_red_traffic_light == 3
                        Type_of_red_traffic_light == Traffic_light_type
                    then
                        if
                            23@ == 1
                        then
                            23@ = 2
                        else
                            if
                                23@ == 3
                            then
                                if
                                    player.Defined($PLAYER_CHAR)
                                then
                                    if
                                        810F:   not player $PLAYER_CHAR wanted_level > 0 
                                    then
                                        if
                                            gosub @CHECK_ANY_COP_NEAR_PLAYER
                                        then
                                            010D: set_player $PLAYER_CHAR wanted_level_to 1
                                        end
                                    end                                                                                  
                                end                                   
                                23@ = 0
                            end
                        end    
                    else
                        23@ = 0
                    end        // type == type
                else
                    23@ = 0 
                end // siren on
            else
                23@ = 0
            end
        else
            23@ = 0
        end
    else
        23@ = 0
    end // player defined
end // while main
//-----------------------------------------------------------------------------------------

:GET_RANDOM_OBJECT
if
    0AE3: 9@ = random_object_near_point 0@ 1@ 2@ in_radius 30.0 find_next 0
then
    repeat
        0984: 31@ = object 9@ model
        if and
            31@ <> 3855  //   GAY_TRAFFIC_LIGHT      +
            31@ <> 1315  //   TRAFFICLIGHT1          +
            31@ <> 1352  //   CJ_TRAFFIC_LIGHT3      +
            31@ <> 1350  //   CJ_TRAFFIC_LIGHT4      +
            31@ <> 1351  //   CJ_TRAFFIC_LIGHT5      +
            31@ <> 3516  //      VGSSTRIPTLIGHTS1    +
            31@ <> 1283  //       MTRAFFIC1          +
        then
            if
                31@ <> 1284   //      MTRAFFIC2      +
            then
                31@ = 0
            end
        end
        if
            31@ <> 0
        then
            object.StorePos(9@ 12@ 13@ 26@)
            0509: 14@ = distance_between_XY 0@ 1@ and_XY 19@ 20@ 
            0509: 3@ = distance_between_XY 0@ 1@ and_XY 12@ 13@        
            if
                0025:   14@ > 3@ // (float)     
            then
                0485: return_true
                return
            end
        end
    until 8AE3: 9@ = random_object_near_point 0@ 1@ 2@ in_radius 30.0 find_next 1
end
8485: return_false
return

:CHECK_ANY_COP_NEAR_PLAYER
if
    0AE1: 21@ = random_actor_near_point 0@ 1@ 2@ in_radius 50.0 find_next 0 pass_deads 1 //IF and SET
then
    repeat
        089F: get_actor 21@ pedtype_to 16@ 
        if and
            16@ == 6
            0364: actor 21@ spotted_actor $PLAYER_ACTOR
        then
            0485: return_true
            return
        end
    until 8AE1: not 21@ = random_actor_near_point 0@ 1@ 2@ in_radius 50.0 find_next 1 pass_deads 1 //IF and SET
end
8485: return_false
return